package com.lykj.common.config;

import com.lykj.core.secure.registry.SecureRegistry;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置
 *
 * @author cxl
 */
@Configuration
public class LykjConfiguration implements WebMvcConfigurer {

	/**
	 * 安全框架配置
	 */
	@Bean
	public SecureRegistry secureRegistry() {
		SecureRegistry secureRegistry = new SecureRegistry();
		secureRegistry.setEnabled(true);
		secureRegistry.excludePathPatterns("/lykj-auth/**");
		secureRegistry.excludePathPatterns("/lykj-system/menu/routes");
		secureRegistry.excludePathPatterns("/lykj-system/menu/auth-routes");
		secureRegistry.excludePathPatterns("/lykj-system/menu/top-menu");
		secureRegistry.excludePathPatterns("/lykj-system/tenant/info");
		secureRegistry.excludePathPatterns("/lykj-flow/process/resource-view");
		secureRegistry.excludePathPatterns("/lykj-flow/process/diagram-view");
		secureRegistry.excludePathPatterns("/lykj-flow/manager/check-upload");
		secureRegistry.excludePathPatterns("/doc.html");
		secureRegistry.excludePathPatterns("/js/**");
		secureRegistry.excludePathPatterns("/webjars/**");
		secureRegistry.excludePathPatterns("/swagger-resources/**");
		secureRegistry.excludePathPatterns("/druid/**");

		secureRegistry.excludePathPatterns("/lykj-shop/store/index");
		secureRegistry.excludePathPatterns("/lykj-shop/store/version");
		secureRegistry.excludePathPatterns("/lykj-shop/store/bootScreen");
//		secureRegistry.excludePathPatterns("/lykj-shop/store/bonusCalendar/update");

		secureRegistry.excludePathPatterns("/lykj-desk/notice/page");
		secureRegistry.excludePathPatterns("/lykj-desk/notice/detail");
		secureRegistry.excludePathPatterns("/lykj-shop/user/register");
		secureRegistry.excludePathPatterns("/lykj-shop/store/category/page");
		secureRegistry.excludePathPatterns("/lykj-shop/store/category/tree");
		secureRegistry.excludePathPatterns("/lykj-shop/store/product/page");
		secureRegistry.excludePathPatterns("/lykj-shop/store/product/info");

		secureRegistry.excludePathPatterns("/lykj-shop/zn/sendRegisterVerifyCode");
		secureRegistry.excludePathPatterns("/lykj-shop/zn/resetLoginPwd");
		secureRegistry.excludePathPatterns("/lykj-shop/zn/sendVerifyCode");
		secureRegistry.excludePathPatterns("/lykj-shop/zn/makerRecordSumInfo");
//		secureRegistry.excludePathPatterns("/lykj-shop/zn/*");

		secureRegistry.excludePathPatterns("/lykj-shop/user/activate");

		secureRegistry.excludePathPatterns("/lykj-shop/user/order/importData");
		return secureRegistry;
	}

	/**
	 * 跨域配置
	 */
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/cors/**")
			.allowedOrigins("*")
			.allowedHeaders("*")
			.allowedMethods("*")
			.maxAge(3600)
			.allowCredentials(true);//允许跨域
	}

}
